home *** CD-ROM | disk | FTP | other *** search
- #define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
- #define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
- #include "DebugUtils.h"
-
- #include <Errors.h>
- #include <LowMem.h>
- #include "ContextUtils.h"
- #include "DisplayManager.h"
- #include "DesktopDoubler.h"
- #include "Nub.h"
- #include "PatchHarness.h"
- #include "ProcInfo.h"
-
-
-
-
-
- #define DISPLAY_COUNT 2
-
-
-
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- static OSStatus InitDisplayManager(UInt32 numVirtualDisplays);
- static void TermDisplayManager(void);
-
- static pascal void DMFinalInitPatch(void);
- static pascal void GetMousePatch(Point *mouseLoc,GetMouseProcPtr getMouseProc);
- static pascal SInt32 MenuSelectPatch(Point startPt,MenuSelectProcPtr menuSelectProc);
- static pascal void SynchIdleTimePatch(void);
- static pascal void DMNotifier(AppleEvent *aevent);
- static void CheckForConfigChange(DisplayIDType displayID,AEDesc *oldConfig,AEDesc *newConfig);
-
- #ifdef __cplusplus
- }
- #endif
-
-
-
-
-
- #if GENERATINGPOWERPC
- static RoutineDescriptor gDMFinalInitPatchRD = BUILD_ROUTINE_DESCRIPTOR(uppDMFinalInitPatchProcInfo,DMFinalInitPatch);
- static RoutineDescriptor *gDMFinalInitPatchUPP = (RoutineDescriptor*)&gDMFinalInitPatchRD;
- static RoutineDescriptor gGetMousePatchRD = BUILD_ROUTINE_DESCRIPTOR(uppGetMousePatchProcInfo,GetMousePatch);
- static RoutineDescriptor *gGetMousePatchUPP = (RoutineDescriptor*)&gGetMousePatchRD;
- static RoutineDescriptor gMenuSelectPatchRD = BUILD_ROUTINE_DESCRIPTOR(uppMenuSelectPatchProcInfo,MenuSelectPatch);
- static RoutineDescriptor *gMenuSelectPatchUPP = (RoutineDescriptor*)&gMenuSelectPatchRD;
- static RoutineDescriptor gSynchIdleTimePatchRD = BUILD_ROUTINE_DESCRIPTOR(uppSynchIdleTimePatchProcInfo,SynchIdleTimePatch);
- static RoutineDescriptor *gSynchIdleTimePatchUPP = (RoutineDescriptor*)&gSynchIdleTimePatchRD;
- static RoutineDescriptor gDMNotifierRD = BUILD_ROUTINE_DESCRIPTOR(uppDMNotificationProcInfo,DMNotifier);
- static RoutineDescriptor *gDMNotifierUPP = (RoutineDescriptor*)&gDMNotifierRD;
- #else
- static DMFinalInitPatchUPP gDMFinalInitPatchUPP = DMFinalInitPatch;
- static GetMousePatchUPP gGetMousePatchUPP = GetMousePatch;
- static MenuSelectPatchUPP gMenuSelectPatchUPP = MenuSelectPatch;
- static SynchIdleTimePatchUPP gSynchIdleTimePatchUPP = SynchIdleTimePatch;
- static DMNotificationUPP gDMNotifierUPP = DMNotifier;
- #endif
-
-
- extern NubInfo *gInfo;
- DisplayManager *gDMan = NULL;
-
-
-
-
-
- OSStatus InitDesktopDoubler(void)
- {
- OSStatus err;
-
-
- // Install patches.
- err = InstallPatch(gInfo->patchList,'DMFI',(UniversalProcPtr)gDMFinalInitPatchUPP);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InstallPatch _DisplayManager failed: %ld\n",err);
- return err;
- }
-
- err = InstallPatch(gInfo->patchList,'DMNt',(UniversalProcPtr)gDMNotifierUPP);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InstallPatch DMNotifer failed: %ld\n",err);
- return err;
- }
-
- err = InstallPatch(gInfo->patchList,'GetM',(UniversalProcPtr)gGetMousePatchUPP);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InstallPatch _GetMouse failed: %ld\n",err);
- return err;
- }
-
- err = InstallPatch(gInfo->patchList,'MenS',(UniversalProcPtr)gMenuSelectPatchUPP);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InstallPatch _MenuSelect failed: %ld\n",err);
- return err;
- }
-
- err = InstallPatch(gInfo->patchList,'IDLE',(UniversalProcPtr)gSynchIdleTimePatchUPP);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InstallPatch _SynchIdleTime failed: %ld\n",err);
- return err;
- }
-
- #if APPBUILD
- err = InitDisplayManager(DISPLAY_COUNT);
- if (err != noErr)
- {
- dprintf(kDConPrefix "InitDisplayManager failed: %ld\n",err);
- return err;
- }
- #endif
-
- return noErr;
- }
-
-
-
-
-
- void TermDesktopDoubler(void)
- {
- // Remove patches.
- RemovePatch(gInfo->patchList,'IDLE');
- RemovePatch(gInfo->patchList,'MenS');
- RemovePatch(gInfo->patchList,'GetM');
- RemovePatch(gInfo->patchList,'DMNt');
- RemovePatch(gInfo->patchList,'DMFI');
-
- // Remove virtual displays.
- TermDisplayManager();
- }
-
-
-
-
-
- OSStatus InitDisplayManager(UInt32 numVirtualDisplays)
- {
- OSStatus err;
-
-
- gDMan = new DisplayManager();
- dAssert(gDMan != NULL);
- if (gDMan == NULL)
- return memFullErr;
-
- err = gDMan->Initialize(numVirtualDisplays);
- if (err != noErr)
- {
- delete gDMan;
- gDMan = NULL;
- return err;
- }
-
- return noErr;
- }
-
-
-
-
-
- void TermDisplayManager(void)
- {
- if (gDMan != NULL)
- {
- delete gDMan;
- gDMan = NULL;
- }
- }
-
-
- #if 0
- #pragma mark -
- #endif
-
-
- pascal void DMFinalInitPatch(void)
- {
- GlobalContext globals;
- OSStatus err;
-
-
- // Only do this once.
- if (gDMan != NULL)
- return;
-
- if (true)
- {
- THzContext zone(SystemZone());
-
- err = InitDisplayManager(DISPLAY_COUNT);
- if (err != noErr)
- dprintf(kDConPrefix "InitDisplayManager failed: %ld\n",err);
- }
- }
-
-
-
-
-
- pascal void GetMousePatch(Point *mouseLoc,GetMouseProcPtr getMouseProc)
- {
- CallGetMouseProc(getMouseProc,mouseLoc);
- if (true)
- {
- GlobalContext globals;
-
- gDMan->OffsetMBarMouse(mouseLoc);
- }
- }
-
-
-
-
-
- pascal SInt32 MenuSelectPatch(Point startPt,MenuSelectProcPtr menuSelectProc)
- {
- SInt32 result;
-
-
- if (true)
- {
- GlobalContext globals;
-
- gDMan->SetMBarTracker(LMGetMouseLocation(),true);
- }
-
- result = CallMenuSelectProc(menuSelectProc,startPt);
-
- if (true)
- {
- GlobalContext globals;
-
- gDMan->SetMBarTracker(LMGetMouseLocation(),false);
- }
-
- return result;
- }
-
-
-
-
-
- pascal void SynchIdleTimePatch(void)
- {
- static Boolean reentered = false;
-
-
- // Sanity checks.
- if (reentered || (gDMan == NULL))
- return;
-
- if (true)
- {
- THzContext zone(SystemZone());
-
- reentered = true;
- gDMan->Idle(LMGetMouseLocation());
- reentered = false;
- }
- }
-
-
-
-
-
- pascal void DMNotifier(AppleEvent *aevent)
- {
- GlobalContext globals;
- DescType actualType;
- Size actualSize;
- AEEventClass eventClass;
- AEEventID eventID;
- AEDesc displayNoticeDesc;
- AEDesc displayDesc;
- AEDesc oldConfigDesc;
- AEDesc newConfigDesc;
- long numDisplays,index;
- DisplayIDType displayID;
- OSStatus err;
-
-
- // Verify this event is what were expecting
- actualSize = sizeof(AEEventClass);
- err = AEGetAttributePtr(aevent,
- keyEventClassAttr,
- typeType,
- &actualType,
- (Ptr)&eventClass,
- sizeof(AEEventClass),
- &actualSize);
- if (err || (eventClass != kCoreEventClass))
- return;
-
- actualSize = sizeof(AEEventID);
- err = AEGetAttributePtr(aevent,
- keyEventIDAttr,
- typeType,
- &actualType,
- (Ptr)&eventID,
- sizeof(AEEventID),
- &actualSize);
- if (err || (eventID != kAESystemConfigNotice))
- return;
-
- // Get the display notice record
- err = AEGetParamDesc( aevent,
- kAEDisplayNotice,
- typeAERecord,
- &displayNoticeDesc);
- if (err != noErr)
- return;
-
- // Iterate thru each display in record
- AECountItems(&displayNoticeDesc,&numDisplays);
- for (index = 1;index <= numDisplays;index++)
- {
- err = AEGetNthDesc( &displayNoticeDesc,
- index,
- typeAERecord,
- (AEKeyword*)&displayID,
- &displayDesc);
- if (err == noErr)
- {
- // Get old config and new config
- err = AEGetParamDesc( &displayDesc,
- keyDisplayOldConfig,
- typeAERecord,
- &oldConfigDesc);
- if (err == noErr)
- {
- err = AEGetParamDesc( &displayDesc,
- keyDisplayNewConfig,
- typeAERecord,
- &newConfigDesc);
- if (err == noErr)
- {
- // Call handler with old and new configs
- CheckForConfigChange(displayID,&oldConfigDesc,&newConfigDesc);
-
- AEDisposeDesc(&newConfigDesc);
- }
-
- AEDisposeDesc(&oldConfigDesc);
- }
-
- AEDisposeDesc(&displayDesc);
- }
- }
-
- AEDisposeDesc(&displayNoticeDesc);
- }
-
-
-
-
-
- void CheckForConfigChange(DisplayIDType displayID,AEDesc *oldConfig,AEDesc *newConfig)
- {
- Display *display;
- Rect oldGDRect,newGDRect;
- DescType actualType;
- Size actualSize;
- Boolean changed = false;
- OSStatus err;
-
-
- // Make sure we've got what we need to
- // actually process a config change
- if (gDMan == NULL)
- return;
-
- display = gDMan->FindDisplay(displayID);
- if (display == NULL)
- return;
-
- // Check for moved display
- actualSize = sizeof(Rect);
- err = AEGetParamPtr(oldConfig,
- keyDeviceRect,
- typeQDRectangle,
- &actualType,
- (Ptr)&oldGDRect,
- sizeof(Rect),
- &actualSize);
- if (err == noErr)
- {
- actualSize = sizeof(Rect);
- err = AEGetParamPtr(newConfig,
- keyDeviceRect,
- typeQDRectangle,
- &actualType,
- (Ptr)&newGDRect,
- sizeof(Rect),
- &actualSize);
- if (err == noErr)
- {
- if ((oldGDRect.top != newGDRect.top) || (oldGDRect.left != newGDRect.left))
- {
- display->MoveTo(newGDRect.left,newGDRect.top);
- changed = true;
- }
- }
- }
-
- if (changed)
- gDMan->Refresh();
- }
-